package MyList;

import java.util.Arrays;

public class List implements IOList {

    public int[] array ;
    public int usdSize;
    public final int COPATICY = 10;

    public List(int[] array) {
        this.array = array;
//        this.usdSize = usdSize;
    }

    private void isPosOfIllegal(int pos)
            throws PosIllegal{
        if(pos > this.usdSize || pos < 0){
            throw new PosIllegal("Pos不合法！！");
        }
    }

    private void grow(){
        this.array = Arrays.copyOf(this.array,this.array.length*2);
    }

    @Override
    public void add(int data) {
        if(this.isFull()){
            this.grow();
        }
        this.array[this.usdSize++] = data;
    }

    @Override
    public void add(int pos, int data) {

    }

    @Override
    public boolean contains(int toFind) {
        for (int i = 0; i < array.length; i++) {
            if(this.array[i] == toFind){
                return true;
            }
        }
        return false;
    }

    @Override
    public int indexOf(int toFind) {
        for (int i = 0; i < array.length; i++) {
            if(this.array[i] == toFind){
                return i;
            }
        }
        return -1;
    }

    @Override
    public int get(int pos) {
        return 0;
    }

    @Override
    public void set(int pos, int value) {

    }

    @Override
    public void remove(int toRemove) {

    }

    @Override
    public int size() {
        return this.usdSize;
    }

    @Override
    public void clear() {

    }

    @Override
    public void display() {
        for (int i = 0; i < this.usdSize; i++) {
            System.out.println(this.array[i] + " ");
        } /**/

//        for(int x : array){
//            System.out.println(x + " ");
//        }

    }

    @Override
    public boolean isFull() {
        return this.usdSize == this.array.length;
    }
}
